package cn.tedu.boke.portal.controller;

import cn.tedu.boke.portal.mapper.PostMapper;
import cn.tedu.boke.portal.mapper.UserMapper;
import cn.tedu.boke.portal.model.User;
import cn.tedu.boke.portal.service.IUserService;
import cn.tedu.boke.portal.vo.PostLabelsVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author tedu.cn
 * @since 2021-11-01
 */
@RestController
@Slf4j
@RequestMapping("/boke/admin")
public class AdminController
{
    @Autowired
    private UserMapper userMapper;

    @GetMapping("/showAllUsers")
    public List<User> showAllUsers()
    {
        QueryWrapper<User> query = new QueryWrapper<>();
        query.eq("type", 1);

        List<User> users = userMapper.selectList(query);
        return users;
    }

    @Autowired
    private IUserService userService;

    @GetMapping("/showAllUsers/delete/{userId}")
    public int deleteUserById(@PathVariable Integer userId)
    {
        System.out.println("注销用户id为:" + userId);
        return userService.cleanUserById(userId);
    }

    @GetMapping("/showAllUsers/lock/{userId}")
    public int lockUserById(@PathVariable Integer userId)
    {
        System.out.println("封锁用户id为:" + userId);
        return userService.lockUserById(userId);
    }

    @GetMapping("/showAllUsers/unLock/{userId}")
    public int unLockUserById(@PathVariable Integer userId)
    {
        System.out.println("解封用户id为:" + userId);
        return userService.unLockUserById(userId);
    }


    @Autowired
    private PostMapper postMapper;

    @GetMapping("/showAllPosts")
    public List<PostLabelsVo> showAllPosts()
    {
        List<PostLabelsVo> posts = postMapper.findAllPosts();
        return posts;
    }

}
